package com.iqoo.store.servlet;

import com.iqoo.store.dao.CartDao;
import com.iqoo.store.model.CartItem;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/removeFromCart")
public class RemoveFromCartServlet extends HttpServlet {
    private CartDao cartDao = new CartDao();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int cartId = Integer.parseInt(request.getParameter("cart_id"));
        CartItem cartItem = cartDao.findById(cartId);
        if(cartItem != null) {
            cartDao.delete(cartItem);
        }
        response.sendRedirect("cart.jsp");
    }
}